<template>
  <div class="content">
    <el-button type="primary" style="margin-bottom: 20px" @click="generateCheck"
      >送检</el-button
    >
    <el-table
      border
      v-loading="loading"
      :data="tableList"
      height="400px"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55"> </el-table-column>
      <el-table-column type="index" label="序号" width="50" />
      <el-table-column align="center" label="单据编号" width="240">
        <template #default="scope">
          {{ scope.row.codeNo }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="汇报数量" width="100">
        <template #default="scope">
          {{ blankAttributeDefault(scope.row.reportNums) }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="单据状态" width="100">
        <template #default="scope">
          <dict-tag :options="data_status" :value="scope.row.dataStatus" />
        </template>
      </el-table-column>
      <el-table-column align="center" label="产品编码" width="120">
        <template #default="scope">
          {{ blankAttributeDefault(scope.row.matterFullCode) }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="产品名称" width="150">
        <template #default="scope">
          {{ blankAttributeDefault(scope.row.matterName) }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="助记码" width="150">
        <template #default="scope">
          {{ blankAttributeDefault(scope.row.matterMnemonicCode) }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="规格型号" width="150">
        <template #default="scope">
          {{ blankAttributeDefault(scope.row.matterSpecModel) }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="表面" width="120">
        <template #default="scope">
          {{ blankAttributeDefault(scope.row.surfaceName) }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="滑块数量" width="90">
        <template #default="scope">
          {{ blankAttributeDefault(scope.row.sliderNum) }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="单轨长度(mm)" width="100">
        <template #default="scope">
          {{ blankAttributeDefault(scope.row.monorailLength) }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="滑块总数量" width="120">
        <template #default="scope">
          {{ blankAttributeDefault(scope.row.sliderAllNum) }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="导轨销售总长度(mm)" width="150">
        <template #default="scope">
          {{ blankAttributeDefault(scope.row.monorailAllLength) }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="计量单位" width="100">
        <template #default="scope">
          {{ blankAttributeDefault(scope.row.unitName) }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="辅助数量" width="100">
        <template #default="scope">
          {{ blankAttributeDefault(scope.row.assistNums) }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="辅助单位" width="100">
        <template #default="scope">
          {{ blankAttributeDefault(scope.row.assistUnitName) }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="生产组织" width="150">
        <template #default="scope">
          {{ blankAttributeDefault(scope.row.productionOrganizationName) }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="生产车间" width="150">
        <template #default="scope">
          {{ blankAttributeDefault(scope.row.workshopName) }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="任务执行人" width="150">
        <template #default="scope">
          {{ blankAttributeDefault(scope.row.productionUserName) }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="备注" width="150">
        <template #default="scope">
          {{ blankAttributeDefault(scope.row.matterRemark) }}
        </template>
      </el-table-column>
    </el-table>
    <pagination
      class="pos-absolute pos-bottom-20px pos-right-20px"
      v-show="total > 0"
      :total="total"
      v-model:page="queryParams.page"
      v-model:limit="queryParams.size"
      @pagination="getList"
    />
  </div>
</template>

<script setup>
import {
  pageExecuteProcessReportApi,
  confirmGenerateCheckApi,
} from "@/api/pagesList";
import { blankAttributeDefault } from "@/utils/index";
const { proxy } = getCurrentInstance();
const { data_status } = toRefs(proxy?.useDict("data_status"));

const props = defineProps({
  codeNo: undefined,
});
const total = ref(0);
const queryParams = ref({
  page: 1,
  size: 10,
  taskCodeNo: props.codeNo,
});
const loading = ref(true);
const tableList = ref([]);
/** 获取需求订单分页列表 */
const getList = async () => {
  const res = await pageExecuteProcessReportApi(queryParams.value);

  tableList.value = res.data.data;
  total.value = res.data.total;
  loading.value = false;
  console.log(tableList.value);
};
getList();

let ids = [];

const handleSelectionChange = (val) => {
  ids = val.map((item) => item.id);
};

const generateCheck = async () => {
  ElMessageBox.confirm("是否确认送检?")
    .then(async () => {
      await confirmGenerateCheckApi({ ids });
      // 成功提示
      ElMessage.success("送检成功！");
      getList();
    })
    .catch(() => {
      ElMessage({
        type: "info",
        message: "已取消送检",
      });
    });
};
</script>